package com.util.zip;

/**
 * <br>
 * date：2020/12/26 14:55
 *
 * @author yuanweilin
 * @version 1.0
 * @since JDK 1.8
 */
public class ZipTest {

    public static void main(String[] args) {
        long start = System.currentTimeMillis();
    	 // 要压缩文件
        String directoryPath = "/Volumes/APFS/Downloads/pdfs";
        // 压缩后路径
        String zipPath = "/Volumes/APFS/Downloads/target" + System.currentTimeMillis() + "-";
//        for (int i = Runtime.getRuntime().availableProcessors(); i > 0; i--) {
//            long beginTime = System.currentTimeMillis();
//            MutithreadZipUtil.createZip(directoryPath, zipPath + i + ".zip", i);
//            long endTime = System.currentTimeMillis();
//            System.out.println("使用 " + i + " 线程，压缩耗时：" + (endTime - beginTime) + "毫秒");
//        }

        zipByRatio(directoryPath, zipPath, 0.67);
//        zipByRatio(directoryPath, zipPath, 0.8);
//        zipByRatio(directoryPath, zipPath, 0.9);
        System.err.println((System.currentTimeMillis() - start)/1000);
    }

    private static void zipByRatio(String directoryPath, String zipPath, double r) {
        long beginTime = System.currentTimeMillis();
        MutithreadZipUtil.createZip(directoryPath, zipPath + r + ".zip", r);
        long endTime = System.currentTimeMillis();
        System.out.println("使用 " + r + " 比例可用线程，压缩耗时：" + (endTime - beginTime) + "毫秒");
    }
}

